﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace appTriangle
{
    public static class clsTriangle
    {
        //private static int _precision = 0;
        
        //public static void SetTrianglePrecision(int precision)
        //{
        //    _precision = precision;
        //}

	    public static void GetTriangleType(double side1, double side2, double side3)
	    {
            double prec = 0.01;
		    if (side1 <=0 || side2 <= 0 || side3 <= 0)
		    {
                Console.WriteLine("Error: Invalid measurements. Cannot form a triangle");
			    return;
		    }

		    if ((side1+side2 > side3) && (side2+side3 > side1) && (side3+side1 > side2))
		    {
			    if ((side1 == side2) && (side2 == side3) && (side3 == side1)) //Checking for Equilateral Triangle
			    {
                    Console.WriteLine("Equilateral Triangle");
			    }
			    else if ((side1 == side2) || (side2 == side3) || (side3 == side1)) //checking for Isosceles Triangle
			    {
                    double aSq = Math.Pow(side1, 2);
                    double bSq = Math.Pow(side2, 2);
                    double cSq = Math.Pow(side3, 2);

                    System.Diagnostics.Debug.WriteLine(aSq);
                    System.Diagnostics.Debug.WriteLine(bSq);
                    System.Diagnostics.Debug.WriteLine(cSq);
 
                    if (
                            (side1 > side2
                                && (side2 >= side3 || side3 >= side2)
                                && (bSq + cSq >= aSq - (prec * aSq)) && (bSq + cSq <= aSq + (prec * aSq)))
                            ||
                            (side2 > side3
                                && (side3 >= side1 || side1 >= side3)
                                && (cSq + aSq >= bSq - (prec * bSq)) && (cSq + aSq <= bSq + (prec * bSq)))
                            ||
                            (side3 > side1
                                && (side1 >= side2 || side2 >= side1)
                                && (aSq + bSq >= cSq - (prec * cSq)) && (aSq + bSq <= cSq + (prec * cSq)))
                        )
                    {
                        Console.WriteLine("Right Isosceles Triangle"); //Triangle is Isosceles and Right triangle.
                    }
                    else
                    {
                        Console.WriteLine("Isosceles Triangle");
                    }
			    }
			    else if ((side1 != side2) && (side2 != side3) && (side3 != side1)) //Checking for Scalene or Right Triangle
			    {
                    double aSq = Math.Pow(side1, 2);
                    double bSq = Math.Pow(side2, 2);
                    double cSq = Math.Pow(side3, 2);
                    if (
                            (side1 > side2
                                && (side2 > side3 || side3 > side2)
                                && (bSq + cSq >= aSq - (prec * aSq)) && (bSq + cSq <= aSq + (prec * aSq)))
                            ||
                            (side2 > side3
                                && (side3 > side1 || side1 > side3)
                                && (cSq + aSq >= bSq - (prec * bSq)) && (cSq + aSq <= bSq + (prec*bSq)))
                            ||
                            (side3 > side1
                                && (side1 > side2 || side2 > side1)
                                && (aSq + bSq >= cSq - (prec * cSq)) && (aSq + bSq <= cSq + (prec * cSq)))
                        )
                    {
                        Console.WriteLine("Right Scalene Triangle");
                    }
                    else
                    {
                        Console.WriteLine("Scalene Triangle");
                    }
                }
		    }
		    else
		    {
                Console.WriteLine("Error: Invalid measurements. Cannot form a triangle");
		    }
	    }

    }
}
